package com.cheetah.start.common.shoesImg;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;

public class ShoeComparisonPipeline {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    public static void main(String[] args) {
        universal();
    }

    private static void extracted() {
        // 1. 加载图片
        Mat shoe1 = Imgcodecs.imread("D:\\xiezi\\4.jpg");
        Mat shoe2 = Imgcodecs.imread("D:\\xiezi\\5.jpg");

        // 2. 去除背景影响
        Mat cleanShoe1 = ContourBasedExtraction.extractShoeByContour(shoe1);
        Mat cleanShoe2 = ContourBasedExtraction.extractShoeByContour(shoe2);

        // 3. 提取背景无关特征
        Mat features1 = BackgroundAgnosticFeature.extractRobustColorHistogram(cleanShoe1);
        Mat features2 = BackgroundAgnosticFeature.extractRobustColorHistogram(cleanShoe2);

        // 4. 计算相似度（排除背景影响）
        double similarity = BackgroundAgnosticComparison.compareShoesRobust(cleanShoe1, cleanShoe2);

        System.out.println("鞋子相似度: " + String.format("%.2f", similarity * 100) + "%");

        // 5. 保存处理后的图片（可选）
        Imgcodecs.imwrite("D:\\xiezi\\4_no_bg.jpg", cleanShoe1);
        Imgcodecs.imwrite("D:\\xiezi\\5_no_bg.jpg", cleanShoe2);
    }



    private static void universal() {
        // 加载任何背景的鞋子图片
        Mat shoe1 = Imgcodecs.imread("D:\\xiezi\\4.jpg");
        Mat shoe2 = Imgcodecs.imread("D:\\xiezi\\5.jpg");

        // 一键对比，自动处理任何背景
        double similarity = UniversalShoeComparison.compareShoesUniversal(shoe1, shoe2);

        System.out.println("鞋子相似度: " + String.format("%.1f", similarity * 100) + "%");

        // 可选：保存背景去除后的图片
        Mat clean1 = UniversalBackgroundRemoval.removeAnyBackground(shoe1);
        Mat clean2 = UniversalBackgroundRemoval.removeAnyBackground(shoe2);
        Imgcodecs.imwrite("D:\\xiezi\\4_no_bg.jpg", clean1);
        Imgcodecs.imwrite("D:\\xiezi\\5_no_bg.jpg", clean2);
    }
}
